package lion.dev.web.useragent;

import java.util.HashMap;
import java.util.Map;

import lion.dev.web.useragent.parser.BrowserParser;
import lion.dev.web.useragent.parser.DescribParser;
import lion.dev.web.useragent.parser.DeviceParser;
import lion.dev.web.useragent.parser.MobileBrowserParser;
import lion.dev.web.useragent.parser.MobileDeviceParser;
import lion.dev.web.useragent.parser.MobileParser;
import lion.dev.web.useragent.parser.OSParser;

/**
 *
 ** <pre>
 * 1  browser
 * 	1.1 crawler
 * 	1.2 mobile
 * 	1.3 console
 * 	1.4 validator
 *  1.5 linkcheck
 *  1.6 offline browser
 *  1.7 email client
 *  1.8 feedreader
 *  1.9 LIBRARIES
 *  1.10 others
 * 2,操作系统
 * 3,device
 * 4，平台
 * desc,描述
 * </pre>
 *
 * @author lion
 * @email hl_0074@sina.com
 * @date 2014年6月6日
 */
public class VisiableFactory {

	private static Map<String, String> browserType = new HashMap<>();
	static {
		browserType.put("1", "BROWSER");
		browserType.put("1.1", "CRAWLER");
		browserType.put("1.2", "MOBILE");
		browserType.put("1.3", "CONSOLE");
		browserType.put("1.4", "VALIDATOR");
		browserType.put("1.5", "LINK CHECKER");
		browserType.put("1.6", "OFFLINE BROWSER");
		browserType.put("1.7", "EMAIL CLIENT");
		browserType.put("1.8", "FEED READER");
		browserType.put("1.9", "LIBRARIE");
		browserType.put("1.100", "OTHERS");
	}

	public static IUAParser create(String type, String desc) {

		IUAParser iUAParser = null;
		if ("1.2".equals(type)) {
			String typeName = browserType.get(type);
			iUAParser = new MobileBrowserParser(desc, typeName);
		} else if ("2".equals(type)) {
			iUAParser = new OSParser(desc);
		} else if ("3".equals(type)) {
			iUAParser = new DeviceParser(desc);
		} else if ("3.1".equals(type)) {
			iUAParser = new MobileDeviceParser(desc);
		} else if ("4".equals(type)) {
			iUAParser = new MobileParser();
		} else if (type.startsWith("1")) {
			String typeName = browserType.get(type);
			if (typeName == null) {
				typeName = "OTHERS";
			}
			iUAParser = new BrowserParser(desc, typeName);
		} else {
			return new DescribParser(desc);
		}

		return iUAParser;
	}
}
